﻿define([], function() {
	return {
		//cookie的调用
		setCookie: function(key, val, expires) {
			var now = new Date();
			now.setDate(now.getDate() + expires);
			document.cookie = key + "=" + val + "; expires=" + now;
		},

		 getCookie:function(key) {
			var cookiestr = document.cookie;
			var list = cookiestr.split("; ");
			for(var attr in list) {
				var kv = list[attr].split("=");
				if(kv[0] == key) {
					return kv[1];
				}
			}
			return "";
		},

		/**

		*/

		 getpageCoord:function(ele) {
			var totalX = 0;
			var totalY = 0;
			totalX += ele.offsetLeft;
			totalY += ele.offsetTop;
			while(ele.offsetParent) {
				ele = ele.offsetParent;
				totalX += ele.offsetLeft;
				totalY += ele.offsetTop;
			}
			/*
			var obj = {
				x : totalX,
				y : totalY
			}
			*/
			return {
				x: totalX,
				y: totalY
			};
		},

		/**
			获取Style属性，解决兼容
		*/
		 getStyle:function(ele) {
			//如果判断是IE？？
			if(ele.currentStyle) {
				return ele.currentStyle;
			} else {
				return getComputedStyle(ele, null); // 
			}
		},

		/**
			获取该元素的所有元素节点
		*/
		getChildElements:function (ele) {
			var newlist = [];
			for(var i = 0; i < ele.childNodes.length; i++) {
				if(ele.childNodes[i].nodeType == 1) {
					newlist.push(ele.childNodes[i]);
				}
			}
			return newlist;
		},

		/**
			根据指定范围，获取随机整数
		*/
		randomInt:function (min, max) {
			return Math.round(Math.random() * (max - min)) + min;
		},
		//设置随机颜色
		randomColor:function () {
			var R = randomInt(0, 255).toString(16);
			var G = randomInt(0, 255).toString(16);
			var B = randomInt(0, 255).toString(16);

			return "#" + (R.length < 2 ? "0" + R : R) + (G.length < 2 ? "0" + G : G) + (B.length < 2 ? "0" + B : B);
		},

		/**
			将一个日期对象变成字符串
		*/
		date2string:function (d, sep, yaobuyao) {
			sep = sep || "-";
			var str = d.getFullYear() + sep + (d.getMonth() + 1) + sep + d.getDate();
			if(yaobuyao) {
				str += " " + d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
				return str;
			} else {
				return str;
			}
		},

		/**
			将一个字符串，变成日期对象
		*/
		string2date:function (str, sep) {
			str = str.replace(sep, "-");
			return new Date(str);
		},

		/**
			计算两个日期之间的差值
		*/
		between:function (start, end, isfix) {
			var totalsecs = Math.abs(start.getTime() - end.getTime()) / 1000;
			return isfix ? Math.round(total / (24 * 3600)) : total / (24 * 3600);
		},
		yzm:function(){
			var col=[0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f","g","q","w","r","t","y","u","i","o","p","s","h","j","k","l","z","x","c","v","n","m","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"];
			var l=col.length;
			//console.log(l);
			var a=Math.floor(Math.random()*l);
			var b=Math.floor(Math.random()*l);
			var c=Math.floor(Math.random()*l);
			var d=Math.floor(Math.random()*l);
			return col[a]+col[b]+col[c]+col[d];
		}
	}	
})

//between(new Date("2016-10-20"), new Date("2016-10-25"), true)